package com.example.mine_platform.controller;

import com.example.mine_platform.commom.Result;
import com.example.mine_platform.pojo.dto.MaterialDTO;
import com.example.mine_platform.pojo.dto.MaterialNewDTO;
import com.example.mine_platform.pojo.entities.Material;
import com.example.mine_platform.pojo.vo.MaterialVO;
import com.example.mine_platform.service.MaterialService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "*")
public class MaterialController {
    @Resource
    private MaterialService materialService;
    @GetMapping("/api/allMaterials")
    public Result getAllMaterials(){
        List<MaterialVO> materialVOList = materialService.getAllMaterials();
        return Result.success(materialVOList);
    }
    @GetMapping("/api/material/{id}")
    public Result getMaterialDetail(@PathVariable Integer id){
        Material material = materialService.getMaterialById(id);
        return Result.success(material);
    }
    @PostMapping("/api/material")
    public Result insertMaterial(@RequestBody MaterialNewDTO materialNewDTO){
        Result result = materialService.insertMaterial(materialNewDTO);
        return result;
    }
    @PutMapping("/api/material")
    public Result updateMaterial(@RequestBody MaterialDTO materialDTO){
        Result result = materialService.updateMaterial(materialDTO);
        return result;
    }
    @DeleteMapping("/api/material/{id}")
    public Result deleteMaterial(@PathVariable Integer id){
        Result result = materialService.deleteMaterial(id);
        return result;
    }
}
